//
//  HomeTableViewController.swift
//  LXQWB
//
//  Created by 江海天 on 2017/7/1.
//  Copyright © 2017年 江海天. All rights reserved.
//

import UIKit

class HomeTableViewController: BaseTableViewController {
	
    override func viewDidLoad() {
        super.viewDidLoad()
		if !isLogin{
			isLoginView?.setView(imageName:nil, imageBackgroudName: nil, title: "panile")
			return
		}
		NotificationCenter.default.addObserver(self, selector: #selector(btnChange), name: XQpresent, object: nil)
		NotificationCenter.default.addObserver(self, selector: #selector(btnChange), name: XQdismiss, object: nil)
		setNav()
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
	
	//MARK: - 内部初始化鸡控制方法
	
	private func setNav(){
		navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendattention", imageBackgroundName: nil,target: self, action: #selector(Home(sender:)))
		navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop", imageBackgroundName: nil,target: self, action: #selector(QRcode(sender:)))
		//title
		
		navigationItem.titleView = titlebtn
	}
	lazy var animator = XQtransitioning()
	@objc private func titleSelected(sender:titleButton){
		
		
		let popover = UIStoryboard(name: "PopoverViewController", bundle: nil).instantiateInitialViewController()
		popover?.transitioningDelegate = animator
		popover?.modalPresentationStyle = .custom
		self.present(popover!, animated: true, completion: nil)
		
		NLog(message: "")
	}
	@objc private func btnChange(){
		titlebtn.isSelected = !titlebtn.isSelected
		
	}

	///二维码
	@objc private func QRcode(sender:UIButton){
		let vc = UIStoryboard(name: "QRcode", bundle: nil).instantiateInitialViewController()
		self.present(vc!, animated: true, completion: nil)
		NLog(message: "")
	}
	
	@objc private func Home(sender:UIButton){
		
		NLog(message: "")
	}
	
	private lazy var titlebtn = { () -> titleButton in
		let titleView = titleButton()
		titleView.setTitle(title: "lxqWB  ")
		titleView.addTarget(self, action: #selector(titleSelected(sender:)), for: UIControlEvents.touchDown)
		titleView.sizeToFit()
		return titleView
		
	}()
	deinit {
		NotificationCenter.default.removeObserver(self)
	}
}
